﻿@page "/DropDown-List/Data-Binding"

@using Syncfusion.Blazor.DropDowns
@using Syncfusion.Blazor.Data

@inherits SampleBaseComponent;

<SampleDescription>
    <p>This sample demonstrates the different data binding supports of the DropDownList. Click the DropDownList element and select an item from the suggestion list. At the very first time, when click on the remote data DropDownList,the loader icon will be shown until the remote request get the data from the server and display it.</p>
</SampleDescription>
<ActionDescription>
    <p>The DropDownList loads the data either from the local data sources, or remote data services that is is through the <a href='https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.DropDowns.IDropDownBase-1.html#Syncfusion_Blazor_DropDowns_IDropDownBase_1_DataSource' target='_blank'> DataSource</a> property. It supports the data type of <code>array</code> or <code>DataManager</code>.</p>
    <p>The DataManager that act as an interface between service endpoint and DropDownList, will require the below minimal information to interact with the service endpoint properly.</p>
    <ul>
        <li><a href='https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.DataManager.html#Syncfusion_Blazor_DataManager_Url' target='_blank'>DataManager->Url</a> - Defines the service endpoint to fetch data.</li>
        <li><a href='https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.DataManager.html#Syncfusion_Blazor_DataManager_Adaptor' target='_blank'>DataManager->Adaptor</a> - Defines the adaptor option. By default,<code>ODataAdaptor</code> is used for remote binding.</li>
    </ul>
    <p>Adaptor is responsible for processing response and request from/to the service endpoint. <code>Syncfusion.Blazor.Data</code> package provides some predefined adaptors that are designed to interact with the particular service endpoints. They are: </p>
    <ul>
        <li><code>UrlAdaptor</code> - Use this to interact any remote services.</li>
        <li><code>ODataAdaptor</code> - Use this to interact with OData endpoints.</li>
        <li><code>ODataV4Adaptor</code> - Use this to interact with OData V4 endpoints.</li>
        <li><code>WebApiAdaptor</code> - Use this to interact with Web API created under OData standards.</li>
        <li><code>WebMethodAdaptor</code> - Use this to interact with web methods.</li>
    </ul>
    <p>In this sample, the local data is bound to a collection of sports data, and the remote data is bound to a collection of data as an instance of <code>DataManager</code>.</p>
    <p>More information on the data binding feature configuration can be found in the <a href='https://blazor.syncfusion.com/documentation/dropdown-list/data-binding/' target='_blank'> documentation section</a>.</p>
</ActionDescription>

<div class="control-section col-lg-12">
    <div id="local-data" class="col-lg-6">
        <div class='content'>
            <h4>Local Data</h4>
            <SfDropDownList TValue="string" TItem="GameFields" PopupHeight="230px" Placeholder="Select a game" DataSource="@Games">
                <DropDownListFieldSettings Text="Text" Value="ID"></DropDownListFieldSettings>
            </SfDropDownList>
        </div>
    </div>
    <div id="remote-data" class="col-lg-6">
        <div class="content">
            <h4>Remote Data</h4>
            <SfDropDownList TValue="string" TItem="OrderDetails" PopupHeight="230px" Placeholder="Select a name" Query="@RemoteDataQuery">
                <SfDataManager Url="https://js.syncfusion.com/demos/ejServices/Wcf/Northwind.svc/Orders" CrossDomain="true" Adaptor="Syncfusion.Blazor.Adaptors.ODataAdaptor"></SfDataManager>
                <DropDownListFieldSettings Text="CustomerID" Value="CustomerID"></DropDownListFieldSettings>
            </SfDropDownList>
        </div>
    </div>
</div>

<style>
    #local-data, #remote-data {
        max-width: 350px;
        margin: 25px 60px;
        padding-top: 15px;
    }
</style>

@code{
    public class GameFields
    {
        public string ID { get; set; }

        public string Text { get; set; }
    }
    public List<GameFields> Games = new List<GameFields>() {
        new GameFields(){ ID= "Game1", Text= "American Football" },
        new GameFields(){ ID= "Game2", Text= "Badminton" },
        new GameFields(){ ID= "Game3", Text= "Basketball" },
        new GameFields(){ ID= "Game4", Text= "Cricket" },
        new GameFields(){ ID= "Game5", Text= "Football" },
        new GameFields(){ ID= "Game6", Text= "Golf" },
        new GameFields(){ ID= "Game7", Text= "Hockey" },
        new GameFields(){ ID= "Game8", Text= "Rugby"},
        new GameFields(){ ID= "Game9", Text= "Snooker" },
        new GameFields(){ ID= "Game10",Text= "Tennis"}
        };
    public Query RemoteDataQuery = new Query().Select(new List<string> { "CustomerID" }).Take(6).RequiresCount();
    public class OrderDetails
    {
        public int? OrderID { get; set; }
        public string CustomerID { get; set; }
        public int? EmployeeID { get; set; }
        public double? Freight { get; set; }
        public string ShipCity { get; set; }
        public bool Verified { get; set; }
        public DateTime? OrderDate { get; set; }
        public string ShipName { get; set; }
        public string ShipCountry { get; set; }
        public DateTime? ShippedDate { get; set; }
        public string ShipAddress { get; set; }
    }
}
